﻿using System;
//using System.Collections.Generic;
using System.Windows.Markup;
using Petra.Gis.Geometry.Support;
using Petra.Gis.ReferenceSystemServices;
using Petra.Gis.ReferenceSystemServices.Transformations;

namespace testSRST
{
  public class testSRSJtsk
  {



    public static ProjectedCoordinateSystem createJTSK_2065()
    {


      //jtsk projected coordinate system...
      // WGS bounds 12.0900, 47.7400, 22.5600, 51.0500
      ProjectedCoordinateSystem cs = new ProjectedCoordinateSystem()
      {

        Axes = new AxisList
        {
          // note for axis directions
          new Axis(){ Name = "X", Orientation = Axis.South},
          new Axis(){ Name = "Y", Orientation = Axis.West}
        },
        Metadata = new Metadata()
        {
          Name = "s-jtsk",
          Authority = "EPSG",
          AuthorityCode = 2065,
          Abbreviation = "s-jtsk",
          Alias = "s-jtsk",
          Remarks = "Czech civil national projected coordinate system"
        },
        DefaultEnvelope = new BoundingBox()
        {
          //Y = 431680, X = 935198; Y = 904554, X=1227672
          Left = 431680,
          Bottom = 935198,
          Right = 904554,
          Top = 1227672
        },
        VerticalDatum = new VerticalDatum()
        {
          Type = VerticalDatum.Unspecified,
          VerticalUnit = DistanceUnit.Meter,
          Metadata = new Metadata()
          {
            Name = "balt po vyrovnani",
            Abbreviation = "bpv",
            Authority = "CUZK",
            AuthorityCode = -1,
            Alias = "bpv",
            Remarks = "baltic after correction, replaces Austrian-Hungarian monarchy Trieste"
          }
        },
        Unit = DistanceUnit.Meter,
        ProjectionDef = new ProjectionDefinition()
        {
          ClassName = "Krovak",
          Metadata = new Metadata()
          {
            Name = "Krovak projection",
            Authority = "CUZK",
            AuthorityCode = -1,
            Abbreviation = "krovak",
            Remarks = "special projection, conformal cone - gauss sphere - bessel ellipsoid"
          },
          //Parameters = new TransformParameters()
          //{
          //  {"alpha", 1.000597498372}
          //}
        },
        // krovak geographic base datum...
        GeographicCoordinateSystem = new GeographicCoordinateSystem()
        {
          Datum = HorizontalDatum.Krovak,
          Axes = new AxisList
          {
            new Axis(){ Name = "E", Orientation = Axis.East},
            new Axis(){ Name = "N", Orientation = Axis.North},
          },
          PrimeMeridian = PrimeMeridian.RoundedFerro,
          Metadata = new Metadata()
          {
            Name = "Krovak geographic space",
            Authority = "CUZK",
            AuthorityCode = -1,
          }
        }

      };

      return cs;

      string outstr;

      outstr = XamlWriter.Save(cs);
      CoordinateSystem c1 = (CoordinateSystem)XamlReader.Parse(outstr);

      //c1.Axes[0].Orientation = Axis.North;
      //c1.Axes[1].Orientation = Axis.East;


      //Krovak t = new Krovak(cs);

      //XYQuadrantTransform qt = new XYQuadrantTransform(
      //cs,
      //c1,
      //new XParam("FlipX", 0),
      //new XParam("FlipY", 0)
      //);

      //qt.Source = cs;
      //qt.Target = c1;


      //CoordinateSystemTransformCache cc = new CoordinateSystemTransformCache();

      //cc.Transforms.Add(t);
      //cc.Transforms.Add(qt);


      //outstr = XamlWriter.Save(cc);


      //SRSTransform t1 = (SRSTransform)XamlReader.Parse(outstr);


    }






    /// <summary>
    /// creates s-jtsk as was defined by intergraph in 1995
    /// axes are "swaped" x<->y and with oposite orientation 
    /// comparing to correct krovak jtsk
    /// purpose of this changes was that ingr system Microstation was unable
    /// to display correct jtsk axes definition and keep north up in map
    /// </summary>
    public static ProjectedCoordinateSystem createJTSK_49()
    {


      //jtsk projected coordinate system...
      // WGS bounds 12.0900, 47.7400, 22.5600, 51.0500
      ProjectedCoordinateSystem cs = new ProjectedCoordinateSystem()
      {

        Axes = new AxisList
        {
          // note for axis directions
          new Axis(){ Name = "X", Orientation = Axis.East},
          new Axis(){ Name = "Y", Orientation = Axis.North}
        },
        Metadata = new Metadata()
        {
          Name = "s-jtsk",
          Authority = "INGR",
          AuthorityCode = 49,
          Abbreviation = "s-jtsk",
          Alias = "s-jtsk ingr",
          Remarks = "Czech civil national projected coordinate system, intergraph definition"
        },
        DefaultEnvelope = new BoundingBox()
        {
          //Y = 431680, X = 935198; Y = 904554, X=1227672
          Left = -904554,
          Bottom = -1227672,
          Right = -431680,
          Top = -935198
        },
        VerticalDatum = new VerticalDatum()
        {
          Type = VerticalDatum.Unspecified,
          VerticalUnit = DistanceUnit.Meter,
          Metadata = new Metadata()
          {
            Name = "balt po vyrovnani",
            Abbreviation = "bpv",
            Authority = "CUZK",
            AuthorityCode = -1,
            Alias = "bpv",
            Remarks = "baltic after correction, replaces Austrian-Hungarian monarchy Trieste"
          }
        },
        Unit = DistanceUnit.Meter,
        ProjectionDef = new ProjectionDefinition()
        {
          ClassName = "Krovak",
          Metadata = new Metadata()
          {
            Name = "Krovak projection",
            Authority = "CUZK",
            AuthorityCode = -1,
            Abbreviation = "krovak",
            Remarks = "special projection, conformal cone - gauss sphere - bessel ellipsoid"
          },
          //Parameters = new TransformParameters()
          //{
          //  {"alpha", 1.000597498372}
          //}
        },
        // krovak geographic base datum...
        GeographicCoordinateSystem = new GeographicCoordinateSystem()
        {
          Datum = HorizontalDatum.Krovak,
          Axes = new AxisList
          {
            new Axis(){ Name = "E", Orientation = Axis.East},
            new Axis(){ Name = "N", Orientation = Axis.North},
          },
          PrimeMeridian = PrimeMeridian.RoundedFerro,
          Metadata = new Metadata()
          {
            Name = "Krovak geographic space",
            Authority = "CUZK",
            AuthorityCode = -1,
          }
        }

      };


      return cs;

      string outstr;

      outstr = XamlWriter.Save(cs);
      CoordinateSystem c1 = (CoordinateSystem)XamlReader.Parse(outstr);


    }





    public static GeographicCoordinateSystem createGeogCS_krovak()
    {

      GeographicCoordinateSystem cs = new GeographicCoordinateSystem()
      {
        Unit = AngularUnit.Degrees,
        Datum = HorizontalDatum.Krovak,
        Axes = new AxisList
        {
          new Axis(){ Name = "E", Orientation = Axis.East},
          new Axis(){ Name = "N", Orientation = Axis.North},
        },
        PrimeMeridian = PrimeMeridian.RoundedFerro,
        Metadata = new Metadata()
        {
          Name = "Krovak geographics coordinate system",
          Authority = "CUZK",
          AuthorityCode = -1,
          Remarks = "this geographic coordinate system is based on Bessel ellipsoid with special prime meridian"
        }

      };


      return cs;
    }


  }
}
